The Absolute Beginners Guide To Amos ------------------------------------- Chapter Ten ----------- We are now going to take a good look at Bobs. Bob is short for Blitter Object, don`t confuse Bobs with sprites, my advice, at this stage at least, is to forget about Sprites, they are a bit harder to use, but they will have their uses as you may find out in the distant future. A Bob is an object under the users or computers control such as the ship you fire in Space Invaders or the Gobbler you control in Pacman, Bobs can also be the enemy Invaders etc. Bobs in fact can be any moving object you wish. To start with we will have to either create our own bobs in an art package like Dpaint or use some existing ones already on disk. Luckily on this very disk in the BOBS drawer we have a bob file called SPACECRAFT.ABK. The ABK by the way stands for Amos Memory Bank. If you want to create your own bobs then as I mentioned you will have to draw them in an art program, save the bobs as an IFF picture, load the IFF picture into the Amos Sprite Grabber program, cut them out and save them as an ABK file. You can then load the ABK file into bank 1 of your program. It`s not as complicated as I have just made it sound really. Our first mission then is to load our bobs into a memory bank. Bank one is especially reserved as a sprite or bob bank. By the way you can load other files into bank 1 if you do not need bobs or sprites in your program. LOAD "DF0:BOBS/SPACECRAFT.ABK" -------------------------- This will load the ABK file into bank one. How does Amos know which bank to load it in? You may ask! Amos examines the file and sees it is a sprite or bob bank file and so loads it into the default bank which as I mentioned earlier is bank one. We have our bobs loaded into bank one, the next step is to ready the screen for printing our bob onto, FLASH OFF: CURS OFF: HIDE: PAPER 0: CLS 0 ----------------------------------------- If we didn`t turn FLASH OFF (remember colour number three?) Then any part of our bob that appeared in colour three may flash, we do not need the text cursor or the mouse for this particular program so we disable these, set the paper colour to 0 (usually black, depending on the palette) and CLear the Screen to colour zero (black) as well. GET SPRITE PALETTE ------------------- NOTE: In Amos pro you can use GET BOB PALETTE but in the original Amos it is still called SPRITE, don`t let this confuse you, as they are the same, OK?. This takes the colours used by the bobs in bank one and replaces Amos`s default colours, the simplest way to understand this is to put a REM or a ` in front of the GET SPRITE PALETTE command, this will stop Amos executing that line and you will see the effect, a load of garbled colours, this is because Amos is displaying the bob in the default colours and not the colours that the bobs were originally drawn in. Remember this technique of putting REMs or `s in front of lines, it`s a useful way of debugging programs without actually deleting lines, useful things those REMs. BOB 1,10,100,1 -------------- Blimey! that looks complicated, yes, it looks it but it`s fairly straight forward really, please make a note of the following because I doubt very much if you will remember this first time. I will now break down each part of the line, BOB 1 This tells Amos that we wish to use a bob, the 1 is really for our reference because we can have up to 64 bobs on screen at once and we have to have a number to refer to each one individually. It is possible to have more than 64 bobs on screen with some twiddling but a maximum of 64 is enough for now don`t you think?. 10,100 Remember the LOCATE 0,10: instruction? This is virtually the same except now we are using pixels instead of bytes as coordinates, there are eight pixels to a byte so the range is eight times the width and length of text coordinates, don`t harp about this at this stage it`s not that vital to understand as with a bit of experimenting you will get used to the idea. So the above line means place the bob at 10 pixels across the screen and 100 pixels down the screen. To recap so far we have, BOB 1, Tell Amos what bob number we are calling this BOB 1,10,100 Place our bob 1 at 10 across and 100 down on the current screen. The last number ,1, is the actual bob image from the bob bank that we want displayed on the screen. Experiment by changing the last number to see what different bobs we have stored in the bank. A better way of viewing bobs is to load the Sprite_editor from your Amos disk and press L to load a bob bank and view/edit them from there. CLEAR KEY: WAIT KEY ------------------ CLEAR the KEYboard buffer and wait for a key press. LISTBANK -------- Just there to show you what is in the bank. That wasn`t so bad after all, the only confusion may arise from the actual BOB command itself so I will give you a few examples to make things a little clearer: BOB 1,0,0,1 Place BOB at 0 across 0 down image 1 (top left of screen) BOB 2,10,10,1 Place another copy of image 1 at 10,10 BOB 1,10,100,1 Place our bob 1 (the one at top left of screen) at 10,100 Amos will automatically erase the old bob 1 at 0,0 for you BOB 2,200,100,2 Place bob 2 (which was at 10,10) to 200,100 but also change its image to the bob in slot 2 of the bank. Amos erases the bob at 10,10. I hope that answers a few questions for you. Here is the complete listing. REM EXAMPLE10.Amos FLASH OFF: CURS OFF: PAPER 0: HIDE: CLS 0 LOAD "DF0:BOBS/SPACECRAFT.ABK" GET SPRITE PALETTE BOB 1,10,100,1 CLEAR KEY: WAIT KEY LISTBANK Please spend a while playing around with EXAMPLE10.Amos as you will learn an awful lot about bobs, and keep taking down those valuable notes. Now placing a bob on screen is fine first time but hardly earth shattering is it? So to pep things up how about animating the spacecraft a little? Hmm spacecraft don`t move about a lot in flight except in one direction I suppose but that blue flame from the engine could be made to look better if it was animated, let`s do that then, as it happens, in the bob bank, images one to four are exact copies of the ship with the blue flame just slightly altered, now if we were to place image two on top of image one quickly then image three over image two etc. It would appear the flame was moving. Remember those flicker books years ago? Something like that. You will probably suspect this is going to entail a major coding session and if we were using almost any other language it would, but with good old Amos things are a lot easier. We will take the listing from EXAMPLE10.Amos and add just three lines to achieve our objective, this is the program in full. REM EXAMPLE10_1.Amos FLASH OFF: CURS OFF: PAPER0: HIDE: CLS 0 LOAD "DF0:BOBS/SPACECRAFT.ABK" GET SPRITE PALLETE CHANNEL 1 to BOB 1 BOB 1,10,100,1 ANIM 1,"(1,5)(2,5)(3,5)(4,5)L" ANIM ON CLEAR KEY: WAIT KEY LISTBANK Here follows a breakdown of the three new lines, CHANNEL 1 TO BOB 1 ------------------ This weird looking monster is necessary to tell Amos we are about to do some ANIMating, you don`t need to understand how it works at the moment but you need to understand that it is needed to use ANIMations, as this is the first time in this program that we are to use a CHANNEL we may as well use CHANNEL 1, and the starting bob we are about to use is bob 1 so we use CHANNEL 1 to BOB 1. This command tells Amos to set up an interrupt channel, as you have probably never heard of interrupts, I will explain briefly. An Interrupt is like having two programs running at once, your normal Amos program and let us say an ANIMation, we set the ANIMation to be interrupt driven (that is what CHANNEL does) and this means every 50th of a second Amos will execute the ANIMation without slowing down your Amos program. The beauty of interrupts are once you have set them up you can forget all about them and they will keep on running unless you tell them to stop. To prove this, RUN EXAMPLE10_1.Amos and press a key to stop the program running, now press escape and you will see the ANIMation still running under interrupt in the background. ANIM 1,"(1,5)(2,5)(3.5)(4,5)L" ------------------------------ The ANIMation line itself looks very complicated at first so as usual I will break it down for you, ANIM 1 Tell Amos there is going to be an ANIMation string, as it`s our first ANIM string we will name it 1. (1,5) Display bob image number 1 and hold it on screen for 5/50ths of a second. (2,5) Display bob 2 and hold for 5/50ths (3,5) bob 3, 5/50ths (4,5) And lastly display bob 4 for 5/50ths of a second L The L is short for Loop and this means once Amos has finished displaying image 4 for 5/50ths of a second it will start all over again from image 1. Don`t forget you must have all the quotes, commas and brackets exactly as in the example or you will probably get an error. ANIM ON ------- Nothing will actually happen visually until this instruction has been executed it simply sets the ANIMation on it`s way, if we have more than one ANIMation in the same program ANIM ON would set ALL the ANIMations in motion So if you didn`t want that you would call each ANIMation string by it`s number i.e. ANIM ON 1. To turn off an ANIMation we use ANIM OFF or ANIM OFF N. (N being your Anim number) Now I will show you the easiest way to make an ANIMated bob MOVE about the screen. The following program will use a space picture as a background screen, place a bob just outside the edge of the screen and then MOVE the bob across the screen the bob will then stop and be blown up with an ANIMated explosion and sound effect, the listing is identical in places to EXAMPLE10_1.Amos. REM A small space animation FLASH OFF: CURS OFF: PAPER 0: HIDE: CLS 0 DOUBLE BUFFER LOAD "DF0:BOB/SPACECRAFT.ABK" LOADIFF "DF0:PICS/SPACE.IFF",0 CHANNEL 1 TO BOB 1 CHANNEL 2 TO BOB 1 BOB 1,-48,20,1 ANIM 1,"(1,5)(2,5)(3,5)(4,5)L" ANIM 2,"(17,5)(18,5)(19,5)(20,5)(21,5)(22,5)(23,5)(24,5)(25,5)" ANIM ON 1 MOVE X 1,"(1,1,370)" MOVE ON WAIT 300 MOVE OFF ANIM OFF 1 ANIM ON 2 BOOM WAIT 25 ANIM OFF:BOB OFF CLEAR KEY: WAIT KEY Looks a right old mess doesn`t it? It is not as complicated as it looks, trust me. I am going to do the breakdown as usual so here we go. FLASH OFF: CURS OFF: PAPER 0: HIDE: CLS 0 ----------------------------------------- I shouldn`t need to explain this. DOUBLE BUFFER ------------- To be honest I didn`t actually need to use this command because we are only using one bob at a time, but DOUBLE BUFFER, in a nutshell, stops your bobs from flickering. I won`t go into the technical side of how it works as that is irrelevant for now and will probably lead to confusion. All you need to know is, if your bobs are flickery then use DOUBLE BUFFER at the start of your program. LOAD "DF0:BOBS/SPACECRAFT.ABK" -------------------------- Load the bobs. LOADIFF "DF0:PICS/SPACE.IFF",0 -------------------------- Load an IFF picture into the current screen, this will be our background picture. Apologies for my artwork, I am not an artist. We covered loading pictures in a previous chapter so look it up or check your notes if need be. CHANNEL 1 TO BOB 1 ------------------ I fully explained this line in the last listing. CHANNEL 2 TO BOB 1 ------------------ We are assigning another interrupt channel for the explosion, as the explosion will overwrite bob 1 we will also use Bob 1 for the explosion, remember not to get the bob number and image number confused. BOB 1,-48,20,1 -------------- Places bob 1 (The ship) at coordinates -48 pixels across and 20 pixels down the screen. I shall explain the minus coordinate, -48 is 48 pixels off of the screen edge so we are placing the ship 48 pixels before the left edge of the screen which means it is not visible. I did this so when we start moving the ship it will appear smoothly from off the screen, a much better effect than the ship just appearing from nowhere. ANIM 1,"(1,5)(2,5)(3,5)(4,5)L" ------------------------------- We covered this exact line in the above example. ANIM 2,"(17,5)(18,5)(19,5)(20,5)(21,5)(22,5)(23,5)(24,5)(25,5)" -------------------------------------------------------------- This is the explosion animation string. It works the same as the ANIM 1 line except it uses more and different images. The explosion animation starts with image 17 and ends at image 25 the delay between each frame is 5/50ths of a second. You could change the delay to a higher number for a faster animation or a lower number for a slower animation. ANIM ON 1 --------- This sets the ships engine flame animation into motion. This time we have had to tell Amos what ANIM to use (1) because there is more than one ANIM string set up. See the ANIM ON line in the last example. MOVE X 1,"(1,1,370)" -------------------- This is the instruction that brings the whole scene to life. I will break this one down further so we can dissect it thoroughly. MOVE X 1, --------- This part tells Amos we wish to move a bob horizontally, the 1 is the bob number we wish to use. "(1,1,370)" ---------- This is the mechanics of the MOVE instruction, the first number (1) is the speed of the movement in 50ths of a second, 1 is the fastest possible. The second (1) is the step count which I have set at one pixel for smooth movement and the 370 is the amount of pixels we want the ship to move across the screen and that is it really. Please take notes on this as to look at it without knowing what the numbers represent can lead to confusion. Remember (Speed,pixels,distance) or as the manual puts it (Speed,Step,Count) whatever suits you. Note: Although I have set the speed of the ships movement to maximum it moves across the screen quite slow, this is because I set the step rate at one pixel for smoothness. If you want an idea of how fast Amos bobs can be change the step rate to 4 8 or 16 etc. And you will be amazed. MOVE ON ------- The previous move instruction just sets up the information for Amos this is the instruction that sets it all in motion. The ship will not MOVE until Amos gets to this line (Remember the same thing with ANIM?) Our spacecraft will now start to move across the screen. WAIT 300 -------- We know what this does, it tells Amos to wait here and do nothing (apart from interrupts of course) For six seconds. The reason I have put this WAIT here is that the next instructions are for the explosion and I want the explosion to occur at the other side of the screen, if we didn`t put this in WAIT 300 the ship would explode almost immediately, try it and see. MOVE OFF -------- We are now preparing for the explosion, the first thing we want to do is stop the ship in it`s tracks, this we achieve with MOVE OFF which turns off all previously set up MOVE strings. If we had more than one MOVE command in the program we would use MOVE OFF N if we only wanted one of the MOVE strings to be halted. ANIM OFF 1 ---------- Turn off the engine flame animation. ANIM ON 2 --------- Start the explosion, ANIM 2. BOOM ---- While the explosion is in progress play the BOOM sound effect. WAIT 25 ------- WAIT for the explosion to finish. ANIM OFF: BOB OFF ---------------- Switch all ANIMations OFF and clear the bob from the screen. CLEAR KEY: WAIT KEY ------------------- Look it up. NOTE: This is the simplest way I could find of doing this short Animation but there are much better (more complicated) ways. ------------------------------------------------------------------------- I am afraid that is just the tip of the iceberg as far as bobs, movement and animation are concerned, it isn`t this tutorials intention to cover everything but I hope to get you off to a good start and understand the basics of it. Here are a few more commands that you will need to know about if you delve further into bobs. MOVE y -------- This works identically to MOVE X, the difference of course is MOVE Y moves the bob vertically along the screen. A minus value would move up the screen and a positive value down the screen. WAIT VBL -------- This causes Amos to WAIT for a Vertical BLank. It basically WAITs for Amos to update the screen which normally happens every 50th of a second, if you have a problem with a bob not appearing try a WAIT VBL instruction before the BOB command. MOVE FREEZE N ------------- Temporarily stop bobs in their tracks, use MOVE ON N to restart. N is optional. ANIM FREEZE N ------------- As above but affects ANIM. Well that`s quite a lot to take in, make those notes and mess with EXAMPLE10.Amos, EXAMPLE10_1.AMOS and EXAMPLE10_2.Amos Have fun. NOTE: The bob file SPACECRAFT.ABK was borrowed from the Amos Extras disk and is located in the AMOS SPRITE_600 folder on that disk along with lots of other useful bobs. The Tracker mod is P.D (author unknown). The background picture I managed myself, sorry. End of chapter ten.